package arithmetic.leetcode;

import java.util.List;
import java.util.Scanner;

/**
 * @author taffywen
 * @date 2022/4/30 22:49
 */
public class Q6删除排序链表重复数据 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] strArry = s.split(",");
        ListNode listNode = new ListNode();

        ListNode currentNode = listNode;
        for (int i = 0; i < strArry.length; i++) {
            currentNode.next = new ListNode(Integer.parseInt(strArry[i]));
            currentNode = currentNode.next;
        }

        ListNode listNode1 = removeRepeatNode(listNode.next);

        while (listNode1 != null){
            System.out.print(listNode1.val + "\t");
            listNode1 = listNode1.next;
        }

    }

    public static ListNode removeRepeatNode(ListNode head){
        ListNode currentNode = head;

        while (currentNode.next != null){
            if (currentNode.val == currentNode.next.val){
                // 当前值跟下一个值相等，就跳过下一个值。即 把当前值的下一个的下一个，替换掉当前值的下一个
                // 没有对 currentNode 重新赋值
                currentNode.next = currentNode.next.next;
            }else {
                // 对 currentNode 重新赋值，这样，下次循环更改的值就是 currentNode.next
                currentNode = currentNode.next;
            }

        }
        return head;
    }
}
